#include <iostream>
#include <string>
using namespace std;

int main()
{
	for (string s; cin >> s && s.front() != '0';) {
		int sum = 0;
		//for (auto c : s) sum += c - '0';
		for (string::iterator it = s.begin(); it != s.end(); ++it) sum += *it - '0';
		sum %= 9;
		if (!sum) sum = 9;
		cout << sum << endl;
	}
	return 0;
}
